<html>
<head><meta charset="utf-8"><title>hover · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html">hover</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="190671355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/190671355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#190671355">(Mar 15 2020 at 22:56)</a>:</h4>
<p>Isn't this <code>exact</code> flag no longer useful in <a href="https://github.com/rust-analyzer/rust-analyzer/blob/af8097f7775e59fd2d61298b6d682788e870c2f9/crates/ra_ide/src/hover.rs#L30" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/af8097f7775e59fd2d61298b6d682788e870c2f9/crates/ra_ide/src/hover.rs#L30"><code>HoverResult</code></a>? There is even no way to set it to <code>false</code> by using the public API and it is never set to <code>false</code> withing the module it is defined in.</p>



<a name="190696877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/190696877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#190696877">(Mar 16 2020 at 09:12)</a>:</h4>
<p>yeah, we should remove it</p>



<a name="190697300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/190697300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#190697300">(Mar 16 2020 at 09:18)</a>:</h4>
<p>There is a PR</p>



<a name="191370892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191370892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191370892">(Mar 21 2020 at 23:42)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> , <span class="user-mention" data-user-id="129457">@Florian Diebold</span>  am I right to suppose that the <code>Ty</code> struct declared in <code>ra_hir_ty</code> should not be visible in <code>ra_ide</code> and instead only interacted through <code>ra_hir::Type</code>?</p>



<a name="191386191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191386191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191386191">(Mar 22 2020 at 08:18)</a>:</h4>
<p>In theory, yes.</p>



<a name="191386193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191386193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191386193">(Mar 22 2020 at 08:18)</a>:</h4>
<p>It's not completely clear if this will work 100%</p>



<a name="191386619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191386619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191386619">(Mar 22 2020 at 08:34)</a>:</h4>
<p>I asked because iirc the are some methods on <code>Type</code> that return structs from <code>ra_hir_ty</code>, but <code>ra_ide</code> doesn't list it as it's dependency, so we can't e.g. match the returned <code>Ty</code> enum</p>



<a name="191386731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191386731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191386731">(Mar 22 2020 at 08:38)</a>:</h4>
<p>they should be changed to use <code>Type</code></p>



<a name="191396270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191396270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191396270">(Mar 22 2020 at 13:16)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> , how would you change this method? <a href="https://github.com/rust-analyzer/rust-analyzer/blob/6fe956420fc63609a84dd005b8190b1f19fff280/crates/ra_hir/src/code_model.rs#L1093-L1096" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/6fe956420fc63609a84dd005b8190b1f19fff280/crates/ra_hir/src/code_model.rs#L1093-L1096">https://github.com/rust-analyzer/rust-analyzer/blob/6fe956420fc63609a84dd005b8190b1f19fff280/crates/ra_hir/src/code_model.rs#L1093-L1096</a></p>



<a name="191396293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191396293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191396293">(Mar 22 2020 at 13:17)</a>:</h4>
<p>I mean, what should it return instead of <code>ra_hir_ty::CallableDef</code>?</p>



<a name="191396354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191396354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191396354">(Mar 22 2020 at 13:18)</a>:</h4>
<p>I would remove it completely, add <code>fn fn_params() -&gt; Vec&lt;(Option&lt;Name&gt;, Type)&gt;; fn fn_ret_type() -&gt; Type</code> accessors to <code>Type</code> and would fix callers to use those instead of <code>CallableDef</code></p>



<a name="191396371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191396371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191396371">(Mar 22 2020 at 13:18)</a>:</h4>
<p>There isn't a reasonable thing we can return there, because there's no defs for things like closures</p>



<a name="191396439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191396439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191396439">(Mar 22 2020 at 13:20)</a>:</h4>
<p>And shouln't we reexport <code>ra_hir_ty</code> stuff from <code>ra_hir</code> <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_hir/src/lib.rs#L63" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_hir/src/lib.rs#L63">here</a>?</p>



<a name="191396931"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191396931" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191396931">(Mar 22 2020 at 13:34)</a>:</h4>
<p>HirDisplay might actually be ok</p>



<a name="191405358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191405358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191405358">(Mar 22 2020 at 17:00)</a>:</h4>
<p>I wish we had some docs on ast node types, at least an example source code that shows to which kind of symbols the node referes to. E.g. the difference between <code>Name</code> and <code>NameRef</code> is not very evident, does <code>ParenType</code> pertain to unnamed tuples or tuple structs too and all these kinds of questions arise... I suppose the <code>ast</code> api is quite stable already so we might want to better document it, <span class="user-mention" data-user-id="133169">@matklad</span> ?</p>



<a name="191405667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191405667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191405667">(Mar 22 2020 at 17:08)</a>:</h4>
<p>SGTM! This probably should be added to ast_src</p>



<a name="191406064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191406064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191406064">(Mar 22 2020 at 17:15)</a>:</h4>
<p>Maybe we could have some kind of doc tests which show example Rust code and what it parses to?</p>



<a name="191406072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191406072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191406072">(Mar 22 2020 at 17:15)</a>:</h4>
<p>We might already have something like that</p>



<a name="191406322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191406322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191406322">(Mar 22 2020 at 17:20)</a>:</h4>
<p>Yeah, that would be wonderful</p>



<a name="191414848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191414848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191414848">(Mar 22 2020 at 20:35)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> , would you mind elaborating on the relationship between <code>ra_hir</code> and <code>ra_hir_def</code>? I see the data structures in <code>ra_hir::code_model</code> are almost literally copy-pasted for <code>ra_hir_def</code>:<br>
<a href="/user_uploads/4715/x_T0RZ2dghhU-07TGzhg-Gfj/image.png" target="_blank" title="image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/x_T0RZ2dghhU-07TGzhg-Gfj/image.png" target="_blank" title="image.png"><img src="/user_uploads/4715/x_T0RZ2dghhU-07TGzhg-Gfj/image.png"></a></div>



<a name="191446937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191446937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191446937">(Mar 23 2020 at 09:09)</a>:</h4>
<p><code>hir</code> is the public API of the all of the compiler logic above syntax trees. It is written in "OO" style. Each type is self contained (as in, it knows it's parents and full context). It should be "clean code".</p>
<p><code>ra_hir_xxx</code> crates are the implementation of the compiler logic. They are written in "ECS" style, with relatively little abstractions. Many types are not self-contained, and explicitelly use local indexes, arenas, etc. </p>
<p><code>ra_hir</code> is what insulates the "we don't know how to actually write an incremental compiler" from the ide with completions, hovers, etc.  It is a (soft, internal) boundary: <a href="https://www.tedinski.com/2018/02/06/system-boundaries.html" target="_blank" title="https://www.tedinski.com/2018/02/06/system-boundaries.html">https://www.tedinski.com/2018/02/06/system-boundaries.html</a>.</p>



<a name="191553871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191553871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191553871">(Mar 24 2020 at 00:05)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> , could you elaborate on why do we store the signature of the closure as <a href="https://github.com/rust-analyzer/rust-analyzer/blob/f9494f114798f66b5f2174cf518a2951a82571d3/crates/ra_hir_ty/src/lib.rs#L707-L708" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/f9494f114798f66b5f2174cf518a2951a82571d3/crates/ra_hir_ty/src/lib.rs#L707-L708">the first parameter type</a>. It appears that we store there the function where this closure was created instead (even nested closure refers to the outer function that declares the closure tree)</p>



<a name="191554427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191554427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191554427">(Mar 24 2020 at 00:13)</a>:</h4>
<p>And am I right, that we don't have <code>hir</code> representation of closures? E.g. the existing <code>ra_hir::Function</code> appears to be a wrapper around <code>ra_hir_def::FunctionId</code>, but closures don't have own <code>ra_hir_def::FunctionId</code> (as they contain only the fn id of the plain function they are declared in as I mentioned above)...</p>



<a name="191558100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191558100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191558100">(Mar 24 2020 at 01:13)</a>:</h4>
<p>My gut feeling is that closure should desugar to a callable struct. Maybe we should introcude:</p>
<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="nc">ra_hir</span>::<span class="n">Closure</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">impl_id</span>: <span class="nc">ra_hir_def</span>::<span class="n">ImplId</span><span class="w"></span>
<span class="w">   </span><span class="c1">// closed state id maybe  ???</span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="191577430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191577430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191577430">(Mar 24 2020 at 08:26)</a>:</h4>
<p>what are you actually trying to do?</p>



<a name="191578277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191578277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191578277">(Mar 24 2020 at 08:34)</a>:</h4>
<p>I was trying to replace <code>ra_hir::Type::as_callable() -&gt; Option&lt;ra_hir_ty::CallableDef&gt;</code> with <code>ra_hir</code>-only types. There is a comment on top of that method that it doesn't work for closures, so I wondered how we should support closures otherwise (e.g. currently we don't show neither call hierarchy, nor call info, nor inlay Param hints for closures)</p>



<a name="191597870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191597870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191597870">(Mar 24 2020 at 11:42)</a>:</h4>
<p>you could certainly create a <code>Closure</code> type in <code>code_model</code> that just points to the containing def and <code>ExprId</code> of the closure</p>



<a name="191686123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191686123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191686123">(Mar 24 2020 at 23:35)</a>:</h4>
<p>Hmm, I am thinking about how this will scale since there should be callable structs (i.e. functors), which are the ADTs that implement <code>Fn*</code> traits. But  I have a feeling we should bother and take closures and callable adts apart</p>



<a name="191728909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191728909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191728909">(Mar 25 2020 at 11:03)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span>  I have a strong feeling that the <code>ra_hir::Type</code> should be an enum, but higher level than <code>ra_hir_ty::Ty</code> and hide it in its impl. We already have <code>ra_hir::Function/Struct/Enum...</code> etc. that should be the members of <code>Type</code> enum. What do you think?</p>



<a name="191729290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191729290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191729290">(Mar 25 2020 at 11:07)</a>:</h4>
<p>E.g. you proposed to add <code>fn_params</code> and <code>fn_ret_type</code>, but both of them should return an option, because now the <code>Type</code> is a general thing and we will and up with a bunch of <code>unwrap()</code> if we want to look at it as a function, by the way these method names are a bit misleading, because closures are not strictly-speaking functions</p>



<a name="191729479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191729479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191729479">(Mar 25 2020 at 11:09)</a>:</h4>
<p>types are not just defs. you'd have to mostly replicate the structure of <code>hir_ty::Ty</code>, and I don't think that would be very useful in the end</p>



<a name="191729513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191729513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191729513">(Mar 25 2020 at 11:09)</a>:</h4>
<p>I am not really sure.... There are a lot of intricate details about types. Like, <code>hir::Struct</code> can be either the ctor function, or a struct. Threading substitutions is tricky. </p>
<p>My current hypothesis is that the IDE would work best with an unitype representation of type, with a methods for specific operations. </p>
<p>Ie, for completion, I think it would be better of completion asks "what fields are available on this type", rather than "match this type with a record, and iterate its fields".</p>



<a name="191729654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191729654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191729654">(Mar 25 2020 at 11:10)</a>:</h4>
<p>I can also imagine a type which you both can call, and which has fields, if we allow for custom Fn impls</p>



<a name="191729737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191729737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191729737">(Mar 25 2020 at 11:11)</a>:</h4>
<p>So this means that we should move more logic from IDE into the <code>Type</code> itself</p>



<a name="191729743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191729743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191729743">(Mar 25 2020 at 11:11)</a>:</h4>
<p>The general design guideline is probably to try to put high-level methods directly onto the <code>Type</code>, like <code>Type::signature</code></p>



<a name="191729768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191729768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191729768">(Mar 25 2020 at 11:11)</a>:</h4>
<blockquote>
<p>So this means that we should move more logic from IDE into the Type itself</p>
</blockquote>
<p>Yup</p>



<a name="191729858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191729858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191729858">(Mar 25 2020 at 11:12)</a>:</h4>
<p>For signature help, you probably want a function that returns the signature for the type. For things like closures, that will even involve trait solving, unless we save the signature during inference</p>



<a name="191729917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191729917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191729917">(Mar 25 2020 at 11:13)</a>:</h4>
<p>part of the problem there is that currently I think signature help displays the function definition as written in the AST, and that's not going to work for things like closures</p>



<a name="191729960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191729960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191729960">(Mar 25 2020 at 11:13)</a>:</h4>
<p>Right, this is what bothers me in the first place. The <code>FunctionSignature</code> in <code>ra_ide</code> works with <code>Function</code>, <code>Struct</code> and <code>EnumVariant</code>, but not <code>Type</code></p>



<a name="191729985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191729985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191729985">(Mar 25 2020 at 11:13)</a>:</h4>
<p>Thus I tried to introduce <code>Closure</code>, but failed...</p>



<a name="191730264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191730264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191730264">(Mar 25 2020 at 11:16)</a>:</h4>
<p>Yeah, that's why <code>Type::as_callable</code> is broken . Rather than trying to downcast the type to a specific def, we should have a function whicih returns a type's signature as a funciton</p>



<a name="191730445"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191730445" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191730445">(Mar 25 2020 at 11:18)</a>:</h4>
<div class="codehilite"><pre><span></span>struct Signature {
    params: Vec&lt;(Option&lt;Name&gt;, Type)&gt;
    ret_ty: Type,
    kind: FnOnce | FnMut | Fn

    // We need a way to extract doc comment, if there is one, but I don&#39;t know what&#39;s the right API

    def: Option&lt;Def&gt;
}

impl Type {
  fn callable_signautre(&amp;self) -&gt; Option&lt;Signature&gt;
}
</pre></div>



<a name="191730646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191730646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191730646">(Mar 25 2020 at 11:20)</a>:</h4>
<p>Also, I wondered, why don't we use <code>Vec&lt;(Option&lt;Pat&gt;, Type)&gt;</code> for <code>params</code>?</p>



<a name="191730650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191730650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191730650">(Mar 25 2020 at 11:21)</a>:</h4>
<p>While I am looking at <code>Type</code>, seems like it might make sense to try to kill <code>Type::autoderef</code> in favor of parameters on methods like <code>fields</code> and <code>iterate methods</code></p>



<a name="191730704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191730704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191730704">(Mar 25 2020 at 11:21)</a>:</h4>
<p>Hm, riiiight, I think that should even be a <code>Local</code> and not <code>Pat</code></p>



<a name="191730967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191730967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191730967">(Mar 25 2020 at 11:24)</a>:</h4>
<p>The more general philosophical guideline here is that, for impl, you usually want a fully-transparent pure-data implementation.</p>
<p>When using an API, it is however more convenient to work with opaque types without any visible internal structure.</p>



<a name="191731275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191731275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191731275">(Mar 25 2020 at 11:28)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133169">matklad</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/hover/near/191730704" title="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/hover/near/191730704">said</a>:</p>
<blockquote>
<p>Hm, riiiight, I think that should even be a <code>Local</code> and not <code>Pat</code></p>
</blockquote>
<p>hmm but what do we do if there's a parameter like <code>(foo, bar): (u32, i32)</code>?</p>



<a name="191731384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191731384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191731384">(Mar 25 2020 at 11:28)</a>:</h4>
<p>like, we don't actually care about the locals of the function, we care about the parameters, and it's not really a 1:1 mapping</p>



<a name="191731526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191731526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191731526">(Mar 25 2020 at 11:30)</a>:</h4>
<p>Right.... Yeah, I guess that needs to be a <code>PatId</code> in the end, plus some public accessor which return whatever an IDE needs</p>



<a name="191731747"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191731747" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191731747">(Mar 25 2020 at 11:32)</a>:</h4>
<p>Hm, I guess that means that, in the limit, we should treat patterns as defs in the code-model API.....</p>
<p>Like, there's little difference between <code>struct Foo { foo: u32, bar: u32}</code> and <code>(foo, bar): (u32, u32)</code></p>



<a name="191732742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191732742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191732742">(Mar 25 2020 at 11:43)</a>:</h4>
<p>for something like signature help, we'd need a) either a string representation of the whole thing or an AST pointer, and b) the type, right?</p>



<a name="191733074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191733074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191733074">(Mar 25 2020 at 11:47)</a>:</h4>
<p>Not sure about strings and ast --- there are macros in patterns: <code>pari!(a, b): (u32, u32)</code>. We might want to render that as <code>(a, b)</code> and not as <code>pair!(a, b)</code></p>



<a name="191733173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191733173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191733173">(Mar 25 2020 at 11:48)</a>:</h4>
<p>hmm but will the macro-expanded pattern always be more clear about what the parameter means? in the end, this is just a hint about the parameter, right, and I'm not convinced that the macro-expanded form is a better hint <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="191733207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191733207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191733207">(Mar 25 2020 at 11:49)</a>:</h4>
<p>but in the end, we won't always have a non-expanded form..</p>



<a name="191733584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191733584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191733584">(Mar 25 2020 at 11:53)</a>:</h4>
<p>This is actually heuristic. For some macros, some users would like to see their unexpanded form in the signature help...</p>



<a name="191733889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191733889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191733889">(Mar 25 2020 at 11:57)</a>:</h4>
<p>I think I'd even argue that the patterns in the function signature are mostly for documentation purposes, otherwise you can always move them into the body. That doesn't really hold for closures though</p>



<a name="191733925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191733925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191733925">(Mar 25 2020 at 11:57)</a>:</h4>
<p>OTOH, maybe we should just do whatever rustdoc does there</p>



<a name="191820432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191820432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191820432">(Mar 25 2020 at 22:47)</a>:</h4>
<p>FYI: rustdoc expands macros and shows the patterns in desugared form <br>
e.g. this</p>
<div class="codehilite"><pre><span></span><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">A</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">a</span>: <span class="kt">u32</span><span class="p">,</span><span class="w"> </span><span class="n">b</span>: <span class="kt">bool</span><span class="p">,</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="n">macro_rules</span><span class="o">!</span><span class="w"> </span><span class="n">pair</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">(</span><span class="cp">$a</span>: <span class="nc">tt</span><span class="p">,</span><span class="w"> </span><span class="cp">$b</span>: <span class="nc">tt</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="cp">$a</span><span class="p">,</span><span class="w"> </span><span class="cp">$b</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="sd">/// My docs!</span>
<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">function</span><span class="p">(</span><span class="n">pair</span><span class="o">!</span><span class="p">(</span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="n">a</span><span class="p">)</span>: <span class="nc">A</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>

<span class="p">}</span><span class="w"></span>
</pre></div>


<p>results in </p>
<div class="codehilite"><pre><span></span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">function</span><span class="p">(</span><span class="n">A</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span>: <span class="nc">b</span><span class="p">,</span><span class="w"> </span><span class="n">a</span>: <span class="nc">a</span><span class="w"> </span><span class="p">}</span>: <span class="nc">A</span><span class="p">)</span><span class="w"></span>
</pre></div>



<a name="191823050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191823050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191823050">(Mar 25 2020 at 23:18)</a>:</h4>
<p>Hmm, what does that ?0 mean, <span class="user-mention" data-user-id="129457">@Florian Diebold</span> ?<br>
<a href="/user_uploads/4715/3KcsGiWvABl2q-3wnORDEz2e/image.png" title="image.png">image.png</a> This comes from <a href="https://github.com/rust-analyzer/rust-analyzer/blob/402bf53a09a3edbb0ff4c94bf22d94d484f81eb9/crates/ra_ide/src/display/function_signature.rs#L181" title="https://github.com/rust-analyzer/rust-analyzer/blob/402bf53a09a3edbb0ff4c94bf22d94d484f81eb9/crates/ra_ide/src/display/function_signature.rs#L181">here</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/3KcsGiWvABl2q-3wnORDEz2e/image.png" title="image.png"><img src="/user_uploads/4715/3KcsGiWvABl2q-3wnORDEz2e/image.png"></a></div>



<a name="191849680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191849680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191849680">(Mar 26 2020 at 08:09)</a>:</h4>
<p>hm, it's a variable, that shouldn't be there</p>



<a name="191967591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/191967591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#191967591">(Mar 27 2020 at 01:00)</a>:</h4>
<p>I struggle to get parameters <code>Vec&lt;PatId&gt;</code> from <code>FunctionId</code>. It seems like this should be stored in <a href="https://github.com/rust-analyzer/rust-analyzer/blob/d2619bf0ca0c8c2ff8cda22beec9851887e4a4d5/crates/ra_hir_def/src/data.rs#L27" title="https://github.com/rust-analyzer/rust-analyzer/blob/d2619bf0ca0c8c2ff8cda22beec9851887e4a4d5/crates/ra_hir_def/src/data.rs#L27"><code>FunctionData</code></a> or how else can I get it? Besides that <code>FunctionData</code> is quite sparse, there is no info about function's abi, unsafety, asynchrony, and maybe more things which I haven't tried to collect yet (maybe there are some other queries for them)</p>



<a name="192004306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/192004306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#192004306">(Mar 27 2020 at 11:26)</a>:</h4>
<p>Patterns matter only for function internals (unlike parameter types), so they belong to the body</p>



<a name="192099783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/192099783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#192099783">(Mar 28 2020 at 02:00)</a>:</h4>
<p>Okay, I managed to get the <code>ra_hir_def::Pat</code>s, for function parameters, but since they contain <code>Idx&lt;Pat&gt;</code> types they make no sense without the <code>Arena&lt;Pat&gt;</code>. <strong>So is it ok exposing them to <code>ra_ide</code>, or otherwise how better to encapsulate them in <code>ra_hir</code>?</strong> .<br>
I would be thinking about smth like:</p>
<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="nc">ra_hir</span>::<span class="n">Pat</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">inner</span>: <span class="nc">ra_hir_def</span>::<span class="n">expr</span>::<span class="n">Pat</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">body</span>: <span class="nc">Arc</span><span class="o">&lt;</span><span class="n">ra_hir_def</span>::<span class="n">Body</span><span class="o">&gt;</span><span class="p">;</span><span class="w"> </span><span class="c1">// this is kinda bad, because we only need body.pats from it, but otherwise we would need to copy the arena</span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>Besides that, the primary goal of getting them was for creating a signature as referenced <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/hover/near/191730445" title="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/hover/near/191730445">here</a> by <span class="user-mention" data-user-id="133169">@matklad</span>  and to use it in signature help afterwards.  But using it this way means displaying the <code>ra_hir_def::Pat</code> and this requires implementing <code>std::fmt::Display</code> for a number of types in <code>ra_hir_def</code>. Whilst for now the signature help uses <code>ast</code> api to display the function parameters patterns and types.</p>
<p>So I want to clarify whether it is okay to move from <code>ast</code> impl to using the <code>ra_hir</code> api (and somehow solve how to expose <code>Pat</code>s) in this case even speaking about the long term design? (My guess is that is what we want, since using the ast api is akin manipulating the raw text but slightly more high-level).</p>



<a name="232267371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232267371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ayomide Bamidele <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232267371">(Mar 29 2021 at 13:28)</a>:</h4>
<p>Hi, I was wondering if there has been any discussion or possibility of providing a feature like <a href="https://github.com/microsoft/vscode-cpptools/issues/1734">https://github.com/microsoft/vscode-cpptools/issues/1734</a> to rust-analyzer? As in hovering over a macro and seeing an "Expands to" in the hover similar to <code>cargo expand</code>. How feasible would this be?</p>



<a name="232267878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232267878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232267878">(Mar 29 2021 at 13:31)</a>:</h4>
<p>This is definitely something we can do, we have an "Expand macro recursively" command already</p>



<a name="232267918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232267918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232267918">(Mar 29 2021 at 13:31)</a>:</h4>
<p>But the output might look quite poor until we implement a formatter</p>



<a name="232268143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232268143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232268143">(Mar 29 2021 at 13:33)</a>:</h4>
<p>On the other hand, rust macro expansion could be very long , and I don't know whether it is good to put it in hover ?</p>



<a name="232268198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232268198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232268198">(Mar 29 2021 at 13:33)</a>:</h4>
<p>Yeah, I suppose it depends on the macro</p>



<a name="232268231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232268231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232268231">(Mar 29 2021 at 13:34)</a>:</h4>
<p>we might want to abbreviate the expansion is it's too long</p>



<a name="232268340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232268340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232268340">(Mar 29 2021 at 13:34)</a>:</h4>
<p>And macros from external crates often just expand to internal code that's hard to read</p>



<a name="232268685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232268685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ayomide Bamidele <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232268685">(Mar 29 2021 at 13:36)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink  [he/him]</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/hover/near/232267878">said</a>:</p>
<blockquote>
<p>This is definitely something we can do, we have an "Expand macro recursively" command already</p>
</blockquote>
<p>Oh I didn't know about this, how can I use this command? My main use case is that I have a proc macro that just generates a bunch of structs and methods, and thought it would be nice if I could hover over the macro call to preview what it expands to. Though maybe if it was just for a few steps -- i.e not expanding derives inside the code that the proc macro generates because that would be very long depending on the macro</p>



<a name="232268734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232268734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232268734">(Mar 29 2021 at 13:37)</a>:</h4>
<p>Could we expand recursively until we hit a macro from a different crate?</p>



<a name="232269006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232269006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232269006">(Mar 29 2021 at 13:39)</a>:</h4>
<blockquote>
<p>My main use case is that I have a proc macro that ...</p>
</blockquote>
<p>That command did not support proc-macro yet, but PR is welcome ! :)</p>



<a name="232269018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232269018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232269018">(Mar 29 2021 at 13:39)</a>:</h4>
<p>proc macros are always from a different crate</p>



<a name="232269064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232269064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232269064">(Mar 29 2021 at 13:39)</a>:</h4>
<p>It does work with function-like proc macros, actually! Not for custom derives though</p>



<a name="232269070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232269070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232269070">(Mar 29 2021 at 13:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/hover/near/232268734">said</a>:</p>
<blockquote>
<p>Could we expand recursively until we hit a macro from a different crate?</p>
</blockquote>
<p>Or expand until we hit a macro that doesn't start with <code>__</code> in the name and is not the same as the current macro? That should be a relatively good heuristic for expanding token munchers and the like while keeping macros that the user would may to read.</p>



<a name="232269204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232269204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232269204">(Mar 29 2021 at 13:40)</a>:</h4>
<p>The best solution here should be a "expand more" button ?</p>



<a name="232269394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232269394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232269394">(Mar 29 2021 at 13:41)</a>:</h4>
<p>For token munchers you would likely have to click on "expand more" for almost every token in the input without this heuristic.</p>



<a name="232269471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232269471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232269471">(Mar 29 2021 at 13:42)</a>:</h4>
<p>Still seems a good idea when applied in combination with the heuristic though.</p>



<a name="232269727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232269727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232269727">(Mar 29 2021 at 13:43)</a>:</h4>
<p>I remember Clion has similar feature</p>



<a name="232270545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232270545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ayomide Bamidele <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232270545">(Mar 29 2021 at 13:48)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216201">Edwin Cheng</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/hover/near/232269006">said</a>:</p>
<blockquote>
<blockquote>
<p>My main use case is that I have a proc macro that ...</p>
</blockquote>
<p>That command did not support proc-macro yet, but PR is welcome ! :)</p>
</blockquote>
<p>How would one go about doing this? Would you reuse the code in <code>ide/expand_macro.rs</code> or would you need to create a new <code>ide/expand_recursive_macro.rs</code>?</p>



<a name="232270862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232270862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ayomide Bamidele <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232270862">(Mar 29 2021 at 13:50)</a>:</h4>
<p>Also, would it be worth me writing up an issue requesting this feature with some brief details about use case? :)</p>



<a name="232271608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232271608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232271608">(Mar 29 2021 at 13:54)</a>:</h4>
<p>I think reuse the code is okay. And I remember there is an issue but I can't find it now :(</p>



<a name="232272564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232272564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232272564">(Mar 29 2021 at 14:00)</a>:</h4>
<p>there's already <a href="https://github.com/rust-analyzer/rust-analyzer/issues/5949">https://github.com/rust-analyzer/rust-analyzer/issues/5949</a></p>



<a name="232273325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232273325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ayomide Bamidele <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232273325">(Mar 29 2021 at 14:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216201">Edwin Cheng</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/hover/near/232269006">said</a>:</p>
<blockquote>
<blockquote>
<p>My main use case is that I have a proc macro that ...</p>
</blockquote>
<p>That command did not support proc-macro yet, but PR is welcome ! :)</p>
</blockquote>
<p>Just tried it with my proc-macro, it seems to work actually! No formatting though</p>



<a name="232273646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232273646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232273646">(Mar 29 2021 at 14:08)</a>:</h4>
<blockquote>
<p>Just tried it with my proc-macro, it seems to work actually! No formatting though</p>
</blockquote>
<p>huh ?</p>



<a name="232273766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232273766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232273766">(Mar 29 2021 at 14:08)</a>:</h4>
<p>Oh, is it a  derive macro ?</p>



<a name="232273916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover/near/232273916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ayomide Bamidele <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.html#232273916">(Mar 29 2021 at 14:10)</a>:</h4>
<p>It's a function-like macro</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>